clear all
capture set more off

/*
* automatically set working directory
foreach i in "Z:/Dropbox/projects/WWI German Discrimination"				///
			 "D:/Dropbox/projects/WWI German Discrimination"				///
			 "C:/Users/anf137/Dropbox/projects/WWI German Discrimination"	///
			 "your directiory" {

			 global path "`i'"
			 confirmdir "$path"
			 if `r(confirmdir)'==0 continue, break
}
*/


*******************************************************************************************************************************************
* FIGURE 1 
*******************************************************************************************************************************************

* This is a scan of two newspaper articles; no replication for this



*******************************************************************************************************************************************
* FIGURE 2 
*******************************************************************************************************************************************

use "$path/Replication/cleaned_data/county_panel_longrun.dta"

preserve
	ren county countyA
	gen county = fipsRC

	* Figure 3A
	ren (Dgermans id) (DgermansA id1)
	xtset fipsRC year, delta(10)
	
	gen Dgermans = D.germanshare
	replace Dgermans = 0 if Dgermans==. & year==1920
	
	* maps with adjustment for pre-war German pop (PANEL A)
	qui reg Dgermans ger1910 
	predict Dgermans2, res
	
	maptile Dgermans2 if year==1920, geo(county1910) n(5) twopt(plotregion(margin(vlarge)) legend(position(4) bmargin(zero))) revcolor
	graph export "$path/Replication/figures/Germanshare_change_popadj.png", replace
	gr close
	
	* PANEL B
	qui reg casrate_1845amm ger1910
	predict casrate_1845amm2, res
	
	maptile casrate_1845amm2 if year==1920, geo(county1910) n(5) twopt(plotregion(margin(vlarge)) legend(position(4) bmargin(zero)))
	graph export "$path/Replication/figures/WWI_casualties_popadj.png", replace
	gr close
restore
	

*******************************************************************************************************************************************
* FIGURE 3 
*******************************************************************************************************************************************

	* Panel a) relationship between WWI casualties and change German pop in 1920
	qui reg Dgermanshareres casrate i.state if year==1920
	local b = round(_b[casrate], 0.001)
	local r2 = round(e(r2), 0.001)

	binscatter Dgermanshareres casrate if year==1920, xtitle("WWI Casualty Rate") ytitle("Change % German Pop. 1910-20") text(0.18 0.625 "beta = `b'") text(0.14 0.63 "R2 = `r2'") control(i.state) yline(0, lc(gs8)) ylab(-0.2(0.1)0.2, gmax gmin) xlab(0(0.1)0.8) graphr(c(white) margin(medsmall)) 
	gr export "$path/Replication/figures/firststage_binscatter_1910-20.pdf", replace
	gr close
	
	* Panel b) relationship between WWI casualties and change German pop in 1910
	qui reg Dgermanshareres casrate i.state if year==1910
	local b = round(_b[casrate], 0.001)
	local r2 = round(e(r2), 0.001)

	binscatter Dgermanshareres casrate if year==1910, xtitle("WWI Casualty Rate") ytitle("Change % German Pop. 1900-10") text(0.18 0.625 "beta = `b'") text(0.14 0.63 "R2 = `r2'") control(i.state) yline(0, lc(gs8)) ylab(-0.2(0.1)0.2, gmax gmin) xlab(0(0.1)0.8) graphr(c(white) margin(medsmall)) 
	gr export "$path/Replication/figures/firststage_binscatter_1900-10.pdf", replace
	gr close
	
	* Panel c) relationship between WWI casualties and change Swedish pop in 1920
	qui reg Dswedeshareres casrate i.state swe1910 if year==1920
	local b = round(_b[casrate], 0.001)
	local j = round(e(r2), 0.001)
	local r2 : display %4.3f `j'

	binscatter Dswedeshareres casrate if year==1920, xtitle("WWI Casualty Rate") ytitle("Change % Swedish Pop. 1910-20") text(0.18 0.625 "beta = `b'") text(0.14 0.63 "R2 = `r2'") control(i.state swe1910) yline(0, lc(gs8)) ylab(-0.2(0.1)0.2, gmax gmin) xlab(0(0.1)0.8) graphr(c(white) margin(medsmall)) 
	gr export "$path/Replication/figures/firststage_binscatter_swedes.pdf", replace
	gr close

	* Panel d) relationship between WWI casualties and change Swedish pop in 1920
	qui reg Ditalianshareres casrate i.state ita1910 if year==1920
	local b = round(_b[casrate], 0.001)
	local r2 = round(e(r2), 0.001)

	binscatter Ditalianshareres casrate if year==1920, xtitle("WWI Casualty Rate") ytitle("Change % Italian Pop. 1910-20") text(0.18 0.625 "beta = `b'") text(0.14 0.63 "R2 = `r2'") control(i.state ita1910) yline(0, lc(gs8)) ylab(-0.2(0.1)0.2, gmax gmin) xlab(0(0.1)0.8) graphr(c(white) margin(medsmall)) 
	gr export "$path/Replication/figures/firststage_binscatter_italians.pdf", replace
	gr close
	
	

*******************************************************************************************************************************************
* FIGURE 4
*******************************************************************************************************************************************

global eventcontrols "c.prewarGer c.draftrate_amm1845#i.year c.prewarPOP#i.year c.prewarMFGL#i.year c.prewarMF#i.year c.prewarurb#i.year"

reghdfe germanshare 1.quincas#i.year 2.quincas#i.year 4.quincas#i.year 5.quincas#i.year $eventcontrols if year>1870, a(id i.year i.year#c.state) cluster(id)


foreach i in 1 5 {
	
	#delimit ;
	coefplot, keep(`i'.quincas*) vertical base omitted
			  graphr(c(white) margin(medsmall)) 
			  mcolor(gs4) yline(0, lcolor(black))
			  ciopts(recast(rcap) lcolor(gs4))
			  rename(`i'.quincas#1880.year = 1880
					 `i'.quincas#1890.year = 1890
					 `i'.quincas#1900.year = 1900
					 `i'.quincas#1910.year = 1910
					 `i'.quincas#1920.year = 1920
					 `i'.quincas#1930.year = 1930
					 `i'.quincas#1940.year = 1940)
					 xline(4.7, lwidth(4) lc(gs14)) ylab(-0.75(0.25)0.75, gmin gmax);
	#delimit cr

	gr export "$path/Replication/figures/quantile`i'_coefplot.pdf", replace
	gr close
	
}
	
	

*******************************************************************************************************************************************
* FIGURE 5
*******************************************************************************************************************************************
use "$path/Replication/cleaned_data/county_panel_shortrun.dta", clear

global controls "c.prewarGer i.year draftrate_amm1845post c.prewarPOP#1.post c.prewarMFGL#1.post c.prewarMF#1.post c.prewarurb#1.post"

areg lnwages c.max_outflow#i.year $controls if year>1890 & S==1, a(id) cluster(id)

	coefplot, keep(*max_outflow*) vertical base omitted	///
			  graphr(c(white) margin(medsmall)) 		///
			  mcolor(gs4) yline(0, lcolor(black)) 		///
			  ciopts(recast(rcap) lcolor(gs4))			///
			  rename(1900.year#c.max_outflow = 1900		///
					 1910.year#c.max_outflow = 1910		///
					 1920.year#c.max_outflow = 1920 	///
					 1930.year#c.max_outflow = 1930		///
					 1940.year#c.max_outflow = 1940)	///
					 xline(2.7, lwidth(4) lc(gs14)) ylab(-0.06(0.02)0.04, gmin gmax)

gr export "$path/Replication/figures/dynamic_wage_effect.pdf", replace
gr close